package com.xiaoxu.yihaoShop.ETLJob;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 *
 * hadoop jar flowJob-1.0-SNAPSHOT.jar com.xiaoxu.yihaoShop.ETLJob.MyETLAppForYARN /data/trackinfo_20130721.data /data/flow
 *
 *
 */

public class MyETLAppForYARN {

    public static void main(String[] args) throws Exception {

        //1.删除输出文件避免报错
        Configuration configuration = new Configuration();
        Path outputPath = new Path(args[1]);
        FileSystem fileSystem = FileSystem.get(configuration);
        if (fileSystem.exists(outputPath)) {
            fileSystem.delete(outputPath, true);
            System.out.println("结果输出文件已被删除");
        }

        //2.配置Job对象
        Job job = Job.getInstance(configuration);
        //设置任务类
        job.setJarByClass(MyETLAppForYARN.class);

        //设置map相关
        job.setMapperClass(ETLMap.class);
        job.setMapOutputKeyClass(NullWritable.class);
        job.setMapOutputValueClass(Text.class);

        //设置输入输出路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, outputPath);

        job.waitForCompletion(true);

    }



}
